<template>
  <div class="products-page">
    <div class="page-header">
      <h2>产品管理</h2>
      <button class="btn-primary">新增产品</button>
    </div>
    
    <div class="stats-bar">
      <div class="stat-item">
        <span class="stat-label">总产品数</span>
        <span class="stat-value">{{ products.length }}</span>
      </div>
      <div class="stat-item">
        <span class="stat-label">在售产品</span>
        <span class="stat-value">{{ activeProducts }}</span>
      </div>
      <div class="stat-item">
        <span class="stat-label">下架产品</span>
        <span class="stat-value">{{ inactiveProducts }}</span>
      </div>
    </div>

    <div class="filters-bar">
      <div class="search-box">
        <input type="text" placeholder="搜索产品..." v-model="searchQuery">
      </div>
      <div class="filter-buttons">
        <button class="filter-btn active">全部</button>
        <button class="filter-btn">在售</button>
        <button class="filter-btn">下架</button>
      </div>
    </div>

    <div class="products-grid">
      <div class="product-card" v-for="product in filteredProducts" :key="product.id">
        <div class="product-image">
          <div class="image-placeholder">📦</div>
        </div>
        <div class="product-info">
          <h3 class="product-name">{{ product.name }}</h3>
          <p class="product-description">{{ product.description }}</p>
          <div class="product-price">
            <span class="current-price">¥{{ product.price }}</span>
            <span class="original-price" v-if="product.originalPrice">¥{{ product.originalPrice }}</span>
          </div>
          <div class="product-stats">
            <span class="stat">库存: {{ product.stock }}</span>
            <span class="stat">销量: {{ product.sales }}</span>
          </div>
          <div class="product-status">
            <span class="status-badge" :class="product.status">{{ product.status === 'active' ? '在售' : '下架' }}</span>
          </div>
          <div class="product-actions">
            <button class="btn-action edit">编辑</button>
            <button class="btn-action view">查看</button>
            <button class="btn-action delete">删除</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'

const searchQuery = ref('')

const products = ref([
  { id: 1, name: '无线蓝牙耳机', description: '高品质音质，长续航', price: 199, originalPrice: 299, stock: 50, sales: 123, status: 'active' },
  { id: 2, name: '智能手表', description: '健康监测，运动追踪', price: 899, originalPrice: 1199, stock: 30, sales: 89, status: 'active' },
  { id: 3, name: '便携充电宝', description: '大容量，快速充电', price: 89, originalPrice: 129, stock: 0, sales: 234, status: 'inactive' },
  { id: 4, name: '无线充电器', description: '支持快充，安全可靠', price: 149, originalPrice: 199, stock: 25, sales: 67, status: 'active' },
  { id: 5, name: '蓝牙音响', description: '360度环绕音效', price: 299, originalPrice: 399, stock: 15, sales: 45, status: 'active' },
  { id: 6, name: '智能手环', description: '运动健康监测', price: 159, originalPrice: 199, stock: 40, sales: 156, status: 'active' },
])

const filteredProducts = computed(() => {
  if (!searchQuery.value) return products.value
  return products.value.filter(product => 
    product.name.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
    product.description.toLowerCase().includes(searchQuery.value.toLowerCase())
  )
})

const activeProducts = computed(() => {
  return products.value.filter(product => product.status === 'active').length
})

const inactiveProducts = computed(() => {
  return products.value.filter(product => product.status === 'inactive').length
})
</script>

<style scoped>
.products-page {
  animation: fadeIn 0.3s ease-in-out;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.page-header h2 {
  color: #2c3e50;
  margin: 0;
  font-size: 28px;
}

.btn-primary {
  background: #3498db;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s ease;
}

.btn-primary:hover {
  background: #2980b9;
}

.stats-bar {
  display: flex;
  gap: 20px;
  margin-bottom: 30px;
}

.stat-item {
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex: 1;
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 14px;
  color: #7f8c8d;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: #2c3e50;
}

.filters-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-box input {
  width: 300px;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
}

.filter-buttons {
  display: flex;
  gap: 8px;
}

.filter-btn {
  padding: 8px 16px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn.active {
  background: #3498db;
  color: white;
  border-color: #3498db;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.product-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.product-image {
  height: 200px;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-placeholder {
  font-size: 48px;
  color: #bdc3c7;
}

.product-info {
  padding: 20px;
}

.product-name {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 8px 0;
}

.product-description {
  color: #7f8c8d;
  margin: 0 0 16px 0;
  font-size: 14px;
}

.product-price {
  margin-bottom: 16px;
}

.current-price {
  font-size: 20px;
  font-weight: 700;
  color: #e74c3c;
  margin-right: 8px;
}

.original-price {
  font-size: 14px;
  color: #95a5a6;
  text-decoration: line-through;
}

.product-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.stat {
  font-size: 12px;
  color: #7f8c8d;
  background: #f8f9fa;
  padding: 4px 8px;
  border-radius: 12px;
}

.product-status {
  margin-bottom: 16px;
}

.status-badge {
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.status-badge.active {
  background: #d5f5e3;
  color: #27ae60;
}

.status-badge.inactive {
  background: #fadbd8;
  color: #e74c3c;
}

.product-actions {
  display: flex;
  gap: 8px;
}

.btn-action {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
  flex: 1;
}

.btn-action.edit {
  background: #3498db;
  color: white;
}

.btn-action.view {
  background: #27ae60;
  color: white;
}

.btn-action.delete {
  background: #e74c3c;
  color: white;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 768px) {
  .stats-bar {
    flex-direction: column;
  }
  
  .filters-bar {
    flex-direction: column;
    gap: 16px;
  }
  
  .search-box input {
    width: 100%;
  }
  
  .products-grid {
    grid-template-columns: 1fr;
  }
}
</style> 